<?php

namespace Modules\Article\Http\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\View\FileViewFinder;
use Modules\Article\Entities\Category;
use Modules\Article\Entities\Content;

class HomeController extends Controller
{
    public function __construct()
    {
        $template = \HDModule::config('article.config.template');
        // $paths = [public_path('templates/' . $template)];
        //设置视图路径
        // \View::setFinder(new FileViewFinder(\App::make('files'), $paths));

        //为了视图能够使用分页 {{$content -> links()}},使用一下方式进行更改默认模板路径
        $finder = app('view')->getFinder();
        $finder->prependLocation(public_path('templates/' . $template));
    }

    public function index()
    {
        return view('index');
        // return redirect('/article/');
    }

    //栏目
    public function list(Category $category)
    {
        //查询数据
        $contents = Content::query()->where('category_id', $category['id'])->paginate(5);
        return view('list', compact('contents', 'category'));
    }

    //文章
    public function content(Content $content)
    {
        return view('content', compact('content'));
    }
}
